﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace PFAGame
{
    class RangedBoss : AMob
    {
        const float projectileSpeed = 10.0f;

        public RangedBoss(float x, float y)
        {
            position.X = x;
            position.Y = y;
            type = e_typeMob.RANGEDBOSS;

            moveRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootRun"), 503, 504, 2, (int)(100 / speed), true);
            moveLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootRun"), 503, 504, 2, (int)(100 / speed), true);
            moveUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootRun"), 503, 504, 2, (int)(100 / speed), true);
            moveDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootRun"), 503, 504, 2, (int)(100 / speed), true);

            attackRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootHit"), 504, 504, 1, (int)(30 * speed), false);
            attackLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootHit"), 504, 504, 1, (int)(30 * speed), false);
            attackUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootHit"), 504, 504, 1, (int)(30 * speed), false);
            attackDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobShoot/MobShootHit"), 504, 504, 1, (int)(30 * speed), false);

            color = Color.Yellow;
            scale = 2.0f;
            radius = 0.8f;
        }

        public override void init()
        {
            base.init();
            range = 10.0f;
            life = 300;
            exp = 40;
        }

        private Vector2 calculateAttackDirection()
        {
            float travelTime = (float)Math.Sqrt(target.getSquaredDistance(position)) / projectileSpeed;
            Vector2 impactPosition = target.Position - target.Direction * travelTime;

            Vector2 projectileDirection = impactPosition - position;
            projectileDirection.Normalize();
            return projectileDirection;
        }

        protected override void attack()
        {
            // instancie un nouveau projectile
            ProjectileRangedRobot projectile = new ProjectileRangedRobot();
            projectile.Position = position;
            Vector2 projectileDirection = calculateAttackDirection();
            projectile.Orientation = projectileDirection;
            projectile.init();
            projectile.Speed *= 2;
            projectile.Speed = projectileSpeed;
            GameplayScreen.Singleton.ProjectileList.Add(projectile);

            RangedRobot.soundInstance[RangedRobot.n++].Play();
            if (RangedRobot.n >= RangedRobot.COUNT_INSTANCE)
                RangedRobot.n = 0;
        }
    }
}
